﻿{% extends "gma/base.html" %}
{% load mytag %}

<!-- CONTENT
  =====================================================================-->

{% block content %}

<div class="page__bd">
    <div class="weui-cells__title">基本数据</div>
    <div class="weui-cells">
        {% if user.avatar %}
        <a class="weui-cell weui-cell_access" href="{% url 'gma:gallery' user.avatar %}">
            <div class="weui-cell__bd"> <p>{{ user.auth_nickname }}</p> </div>
            <div class="weui-cell__ft"> <img src="{{ user.avatar|cdn }}" class="right_large_avatar"> </div>
        </a>
        {% endif %}

        <div class="weui-cell">
            <div class="weui-cell__bd"> <p>用户id</p> </div>
            <div class="weui-cell__ft">{{ user.id }}</div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__bd"> <p>推荐位</p> </div>
            <div class="weui-cell__ft"> {{ recommend_desp }} </div>
        </div>
    </div>
</div>

<div class="weui-btn-area">
    {% if user.recommend_value > 0 %}
        {% if user.recommend_value < max_recommend_value %}
            <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:recommendUser(0)"> <i class="fa fa-angle-double-up"></i> 置顶 </a>
            <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:recommendUser(1)"> <i class="fa fa-angle-up"></i> 排名+1 </a>
        {% endif %}

        {% if user.recommend_value > min_recommend_value %}
            <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:recommendUser(-1)"> <i class="fa fa-angle-down"></i> 排名-1 </a>
        {% endif %}

        <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:cancelRecommendUser()"> <i class="fa fa-undo"></i> 撤销推荐 </a>
    {% elif user.recommend_value < 0 %}
        <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:cancelRecommendUser()"> <i class="fa fa-undo"></i> 撤销置底 </a>
    {% else %}
        <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:recommendUser(0)"> <i class="fa fa-angle-double-up"></i> 置顶 </a>
        <a class="weui-btn weui-btn_block weui-btn_primary" href="javascript:recommendUser(1)"> <i class="fa fa-angle-up"></i> 推荐 </a>
        <a class="weui-btn weui-btn_block weui-btn_warn" href="javascript:unrecommendUser()"> <i class="fa fa-angle-double-down"></i> 置底 </a>
    {% endif %}

    <a class="weui-btn weui-btn_block weui-btn_default" href="{% url 'gma:caster_detail' user.id %}"> 取消 </a>
</div>

<div class="page__ft">
    <a href="{% url 'gma:home' %}">
        <span class="bottom-logo">
           HiBao
       </span>
    </a>
</div>

{% endblock content %}

<!-- SCRIPT
  =====================================================================-->

{% block extra_js %}

<script>

function recommendUser(offset) {
    let url = "{% url 'gma:api_recommend_user' %}";
    let data = {
        'uid': {{ user.id }},
        'offset': offset,
    };

    new my_ajax(url, data, '', '', () => {
        show_toast(`推荐成功!`);
        setTimeout(() => {
            window.location.reload();
        }, 1000);
    });
}

function unrecommendUser() {
    let url = "{% url 'gma:api_unrecommend_user' %}";
    let data = {
        'uid': {{ user.id }},
    };

    new my_ajax(url, data, '', '', () => {
        show_toast(`置底成功!`);
        setTimeout(() => {
            window.location.reload();
        }, 1000);
    });
}

function cancelRecommendUser() {
    let url = "{% url 'gma:api_cancel_recommend_user' %}";
    let data = {
        'uid': {{ user.id }},
    };

    new my_ajax(url, data, '', '', () => {
        show_toast(`撤销成功!`);
        setTimeout(() => {
            window.location.reload();
        }, 1000);
    });
}
</script>

{% endblock extra_js %}